package bb.lanxing.util.route;

import android.content.Context;
import android.graphics.RectF;
import android.os.Handler;
import android.os.Looper;
import android.os.Parcelable;
import android.view.GestureDetector;
import android.view.MotionEvent;
import android.view.View;
import androidx.core.internal.view.SupportMenu;
import com.github.mikephil.charting.charts.LineChart;
import com.github.mikephil.charting.components.AxisBase;
import com.github.mikephil.charting.components.XAxis;
import com.github.mikephil.charting.components.YAxis;
import com.github.mikephil.charting.data.DataSet;
import com.github.mikephil.charting.data.Entry;
import com.github.mikephil.charting.data.LineData;
import com.github.mikephil.charting.data.LineDataSet;
import com.github.mikephil.charting.formatter.IFillFormatter;
import com.github.mikephil.charting.formatter.ValueFormatter;
import com.github.mikephil.charting.highlight.Highlight;
import com.github.mikephil.charting.interfaces.dataprovider.LineDataProvider;
import com.github.mikephil.charting.interfaces.datasets.IDataSet;
import com.github.mikephil.charting.interfaces.datasets.ILineDataSet;
import com.github.mikephil.charting.listener.OnChartValueSelectedListener;
import com.github.mikephil.charting.utils.MPPointD;
import com.github.mikephil.charting.utils.Transformer;
import com.github.mikephil.charting.utils.ViewPortHandler;
import bb.lanxing.R;
import bb.lanxing.databinding.unit.UnitConstants;
import bb.lanxing.lib.widget.utils.Density;
import bb.lanxing.model.database.RouteBookPoint;
import bb.lanxing.model.database.RouteSlope;
import bb.lanxing.util.Log;
import bb.lanxing.util.chart.LineMarkerChartRender;
import bb.lanxing.util.chart.LineMarkerDataSet;
import bb.lanxing.util.chart.MarkerEntry;
import bb.lanxing.util.chart.SimpleChartGestureListener;
import bb.lanxing.util.ui.ChartAnimatedZoomJob;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.List;

public class RouteAltitudeChartHelper {
    private LineDataSet altitudeDataSet;
    private List<Float> distances;
    private Handler handler;
    private int labelCount;
    private LongPressRunnable longPressRun;
    private boolean longPressed;
    private List<RouteBookPoint> lushuPoints;
    private LineChart mChart;
    private OnChartIndicatorUpdateListener onChartIndicatorUpdateListener;
    private OnSlopeSelectedListener onSlopeSelectedListener;
    private List<IDataSet> routeSlopeDateSets;
    private List<RouteSlope> routeSlopes;
    private OnChartScaleListener scaleListener;
    private OnAltitudeSelectedListener selectedListener;
    private List<RectF> slopeRects;

    public RouteAltitudeChartHelper(LineChart chart, boolean zoom, int yLabelCount) {
        this(chart, zoom, yLabelCount, null);
    }

    public RouteAltitudeChartHelper(LineChart chart, boolean zoom, int yLabelCount, OnAltitudeSelectedListener listener) {
        this.handler = new Handler(Looper.getMainLooper());
        this.longPressRun = new LongPressRunnable() {
            float[] pressPoints = new float[2];

            @Override
            public void run() {
                Entry entryForIndex;
                Object data;
                if (RouteAltitudeChartHelper.this.altitudeDataSet == null) {
                    return;
                }
                this.pressPoints[0] = this.x;
                this.pressPoints[1] = this.y;
                Transformer transformer = RouteAltitudeChartHelper.this.mChart.getTransformer(RouteAltitudeChartHelper.this.altitudeDataSet.getAxisDependency());
                transformer.pixelsToValue(this.pressPoints);
                int entryIndex = RouteAltitudeChartHelper.this.altitudeDataSet.getEntryIndex(this.pressPoints[0], Float.NaN, DataSet.Rounding.CLOSEST);
                if (entryIndex == -1 || (data = (entryForIndex = RouteAltitudeChartHelper.this.altitudeDataSet.getEntryForIndex(entryIndex)).getData()) == null || !(data instanceof RouteBookPoint)) {
                    return;
                }
                this.pressPoints[0] = entryForIndex.getX();
                float[] fArr = this.pressPoints;
                fArr[1] = 0.0f;
                transformer.pointValuesToPixel(fArr);
                RouteAltitudeChartHelper.this.onChartIndicatorUpdateListener.onAltitudePressed(this.pressPoints[0], this.y, (RouteBookPoint) data, entryForIndex.getX());
            }
        };
        this.mChart = chart;
        this.labelCount = yLabelCount;
        this.selectedListener = listener;
        initChart(zoom);
    }

    public void setOnChartIndicatorUpdateListener(OnChartIndicatorUpdateListener listener) {
        this.onChartIndicatorUpdateListener = listener;
    }

    public void setOnChartScaleListener(OnChartScaleListener scaleListener) {
        this.scaleListener = scaleListener;
    }

    public void setOnSlopeSelectedListener(OnSlopeSelectedListener onSlopeSelectedListener) {
        this.onSlopeSelectedListener = onSlopeSelectedListener;
    }

    public void initChart(List<RouteBookPoint> lushuPoints, List<Float> distances) {
        this.lushuPoints = lushuPoints;
        this.distances = distances;
        this.altitudeDataSet = setupAltitudeData(lushuPoints, distances);
    }

    public void initSlope(List<RouteSlope> routeSlopes) {
        initSlope(routeSlopes, true);
    }

    public void initSlope(List<RouteSlope> routeSlopes, boolean drawMarker) {
        this.routeSlopes = routeSlopes;
        setupSlopeData(this.lushuPoints, this.distances, routeSlopes, drawMarker);
    }

    private void initChart(boolean zoomable) {
        Context context = this.mChart.getContext();
        int color = context.getResources().getColor(R.color.grey_999999);
        YAxis axisLeft = this.mChart.getAxisLeft();
        boolean z = true;
        axisLeft.setDrawGridLines(true);
        axisLeft.setDrawZeroLine(false);
        axisLeft.enableGridDashedLine(Density.dp2px(context, 2.0f), Density.dp2px(context, 1.0f), 0.0f);
        axisLeft.setLabelCount(this.labelCount, true);
        axisLeft.setTextColor(color);
        ValueFormatter iAxisValueFormatter = new ValueFormatter() {
            private DecimalFormat decimalFormat = new DecimalFormat("0.0");

            @Override
            public String getFormattedValue(float value, AxisBase axis) {
                if (value > 10000.0f) {
                    return ((int) (value / 1000.0f)) + UnitConstants.UNIT_SIZE_KM;
                } else if (value > 1000.0f) {
                    return this.decimalFormat.format(value / 1000.0f) + UnitConstants.UNIT_SIZE_KM;
                } else {
                    return ((int) value) + "m";
                }
            }
        };
        axisLeft.setValueFormatter(new ValueFormatter() {
            @Override
            public String getFormattedValue(float value, AxisBase axis) {
                return String.valueOf(Math.round(value));
            }
        });
        this.mChart.getAxisRight().setEnabled(false);
        XAxis xAxis = this.mChart.getXAxis();
        xAxis.setDrawGridLines(false);
        xAxis.setPosition(XAxis.XAxisPosition.BOTTOM);
        xAxis.setValueFormatter(iAxisValueFormatter);
        xAxis.setAvoidFirstLastClipping(true);
        xAxis.setTextColor(color);
        boolean z2 = this.selectedListener != null;
        this.mChart.getDescription().setEnabled(false);
        this.mChart.setDrawGridBackground(false);
        this.mChart.setHighlightPerDragEnabled(z2);
        this.mChart.setHighlightPerTapEnabled(z2);
        LineChart lineChart = this.mChart;
        if (!z2 && !zoomable) {
            z = false;
        }
        lineChart.setTouchEnabled(z);
        this.mChart.setScaleXEnabled(zoomable);
        this.mChart.setScaleYEnabled(false);
        this.mChart.setDoubleTapToZoomEnabled(false);
        this.mChart.setPinchZoom(false);
        this.mChart.getLegend().setEnabled(false);
        this.mChart.setDrawMarkers(false);
        LineChart lineChart2 = this.mChart;
        LineChart lineChart3 = this.mChart;
        lineChart2.setRenderer(new LineMarkerChartRender(lineChart3, lineChart3.getAnimator(), this.mChart.getViewPortHandler()));
        this.mChart.setOnChartValueSelectedListener(new OnChartValueSelectedListener() {
            @Override
            public void onNothingSelected() {
            }

            @Override
            public void onValueSelected(Entry e, Highlight h) {
                Object data = e.getData();
                if (data == null || !(data instanceof RouteBookPoint) || RouteAltitudeChartHelper.this.selectedListener == null) {
                    return;
                }
                RouteAltitudeChartHelper.this.selectedListener.onAltitudeSelected((RouteBookPoint) data);
            }
        });
        if (zoomable) {
            this.mChart.setOnChartGestureListener(new SimpleChartGestureListener() {
                float[] points = new float[6];
                int touchInterval;

                {
                    this.touchInterval = Density.dp2px(RouteAltitudeChartHelper.this.mChart.getContext(), 5.0f);
                }

                @Override
                public void onChartSingleTapped(MotionEvent me) {
                    if (RouteAltitudeChartHelper.this.slopeRects == null || RouteAltitudeChartHelper.this.routeSlopeDateSets == null) {
                        return;
                    }
                    this.points[0] = me.getX();
                    this.points[1] = me.getY();
                    float[] fArr = this.points;
                    fArr[2] = 0.0f;
                    fArr[3] = 0.0f;
                    fArr[4] = 1.0f;
                    fArr[5] = 1.0f;
                    RouteAltitudeChartHelper.this.mChart.getTransformer(RouteAltitudeChartHelper.this.altitudeDataSet.getAxisDependency()).pixelsToValue(this.points);
                    float[] fArr2 = this.points;
                    float f = fArr2[0];
                    float f2 = (fArr2[5] - fArr2[3]) * this.touchInterval;
                    for (int i = 0; i < RouteAltitudeChartHelper.this.slopeRects.size(); i++) {
                        float[] fArr3 = this.points;
                        if (((RectF) RouteAltitudeChartHelper.this.slopeRects.get(i)).contains(fArr3[0], fArr3[1]) && ((IDataSet) RouteAltitudeChartHelper.this.routeSlopeDateSets.get(i)).getEntryIndex(f, f2, DataSet.Rounding.CLOSEST) != -1) {
                            RouteAltitudeChartHelper.this.zoomSlope(i, true);
                            return;
                        }
                    }
                }

                @Override
                public void onChartScale(MotionEvent me, float scaleX, float scaleY) {
                    super.onChartScale(me, scaleX, scaleY);
                    if (RouteAltitudeChartHelper.this.scaleListener != null) {
                        ViewPortHandler viewPortHandler = RouteAltitudeChartHelper.this.mChart.getViewPortHandler();
                        float scaleX2 = viewPortHandler.getScaleX() * scaleX;
                        float scaleY2 = viewPortHandler.getScaleY() * scaleY;
                        Log.i("chartHelp", "scale X=" + scaleX2 + ", scale Y=" + scaleY2);
                        if (scaleX2 < 1.0f) {
                            scaleX2 = 1.0f;
                        }
                        if (scaleY2 < 1.0f) {
                            scaleY2 = 1.0f;
                        }
                        RouteAltitudeChartHelper.this.scaleListener.onScale(scaleX2, scaleY2);
                    }
                    RouteAltitudeChartHelper.this.handler.removeCallbacks(RouteAltitudeChartHelper.this.longPressRun);
                }

                @Override
                public void onChartTranslate(MotionEvent me, float dX, float dY) {
                    super.onChartTranslate(me, dX, dY);
                    RouteAltitudeChartHelper.this.handler.removeCallbacks(RouteAltitudeChartHelper.this.longPressRun);
                }

                @Override
                public void onChartLongPressed(MotionEvent me) {
                    super.onChartLongPressed(me);
                }
            });
        }
        this.mChart.setOnTouchListener(new View.OnTouchListener() {
            private GestureDetector detector;

            {
                this.detector = new GestureDetector(RouteAltitudeChartHelper.this.mChart.getContext(), new GestureDetector.SimpleOnGestureListener() {
                    @Override
                    public void onLongPress(MotionEvent e) {
                        super.onLongPress(e);
                        RouteAltitudeChartHelper.this.lockChart();
                        RouteAltitudeChartHelper.this.updatePress(e.getX(), e.getY());
                    }
                });
            }

            @Override
            public boolean onTouch(View v, MotionEvent event) {
                boolean z3;
                int action = event.getAction();
                if (action != 1) {
                    if (action == 2) {
                        if (RouteAltitudeChartHelper.this.longPressed) {
                            RouteAltitudeChartHelper.this.updateIndicator(event.getX(), event.getY());
                            z3 = true;
                            return !this.detector.onTouchEvent(event) || z3;
                        }
                    }
                    z3 = false;
                    if (this.detector.onTouchEvent(event)) {
                    }
                }
                if (RouteAltitudeChartHelper.this.longPressed) {
                    RouteAltitudeChartHelper.this.unlockChart();
                }
                z3 = false;
                if (this.detector.onTouchEvent(event)) {
                }
                return z3;
            }
        });
    }

    public void updatePress(float x, float y) {
        if (this.onChartIndicatorUpdateListener != null) {
            this.handler.removeCallbacks(this.longPressRun);
            this.longPressRun.setXY(x, y);
            this.handler.postDelayed(this.longPressRun, 50L);
        }
    }

    public void updateIndicator(float x, float y) {
        LineDataSet lineDataSet;
        Entry entryForIndex;
        Object data;
        if (this.onChartIndicatorUpdateListener == null || (lineDataSet = this.altitudeDataSet) == null) {
            return;
        }
        float[] fArr = {x, y};
        Transformer transformer = this.mChart.getTransformer(lineDataSet.getAxisDependency());
        transformer.pixelsToValue(fArr);
        int entryIndex = this.altitudeDataSet.getEntryIndex(fArr[0], Float.NaN, DataSet.Rounding.CLOSEST);
        if (entryIndex == -1 || (data = (entryForIndex = this.altitudeDataSet.getEntryForIndex(entryIndex)).getData()) == null || !(data instanceof RouteBookPoint)) {
            return;
        }
        fArr[0] = entryForIndex.getX();
        fArr[1] = 0.0f;
        transformer.pointValuesToPixel(fArr);
        this.onChartIndicatorUpdateListener.onAltitudePressed(fArr[0], y, (RouteBookPoint) data, entryForIndex.getX());
    }

    public void lockChart() {
        this.mChart.setDragEnabled(false);
        this.mChart.setScaleXEnabled(false);
        this.mChart.requestDisallowInterceptTouchEvent(false);
        this.longPressed = true;
    }

    public void unlockChart() {
        this.mChart.setDragEnabled(true);
        this.mChart.setScaleXEnabled(true);
        this.mChart.requestDisallowInterceptTouchEvent(true);
        this.longPressed = false;
        OnChartIndicatorUpdateListener onChartIndicatorUpdateListener = this.onChartIndicatorUpdateListener;
        if (onChartIndicatorUpdateListener != null) {
            onChartIndicatorUpdateListener.onIndicatorCanceled();
        }
    }

    private LineDataSet setupAltitudeData(List<RouteBookPoint> lushuPoints, List<Float> distances) {
        int color = this.mChart.getContext().getResources().getColor(R.color.route_chart_fill_color);
        LineDataSet buildAltitudeDataSet = buildAltitudeDataSet(lushuPoints, distances);
        buildAltitudeDataSet.setColor(color);
        buildAltitudeDataSet.setDrawCircles(false);
        buildAltitudeDataSet.setDrawValues(false);
        buildAltitudeDataSet.setLineWidth(0.2f);
        buildAltitudeDataSet.setFillFormatter(new IFillFormatter() {
            @Override
            public float getFillLinePosition(ILineDataSet dataSet, LineDataProvider dataProvider) {
                return dataProvider.getYChartMin();
            }
        });
        buildAltitudeDataSet.setHighLightColor(SupportMenu.CATEGORY_MASK);
        buildAltitudeDataSet.setAxisDependency(YAxis.AxisDependency.LEFT);
        buildAltitudeDataSet.setDrawFilled(true);
        buildAltitudeDataSet.setFillColor(color);
        LineData lineData = new LineData(buildAltitudeDataSet);
        this.mChart.highlightValues(null);
        try {
            this.mChart.setData(lineData);
        } catch (Exception e) {
            e.printStackTrace();
        }
        this.mChart.postInvalidate();
        return buildAltitudeDataSet;
    }

    private void setupSlopeData(List<RouteBookPoint> lushuPoints, List<Float> distances, List<RouteSlope> routeSlopes, boolean drawMarker) {
        Context context;
        Context context2 = this.mChart.getContext();
        ArrayList arrayList = new ArrayList(routeSlopes.size() + 1);
        if (this.altitudeDataSet == null) {
            this.altitudeDataSet = setupAltitudeData(lushuPoints, distances);
        }
        arrayList.add(this.altitudeDataSet);
        YAxis axisLeft = this.mChart.getAxisLeft();
        axisLeft.setAxisMinimum(this.mChart.getYChartMin());
        float f = axisLeft.mAxisRange * 0.05f;
        int size = routeSlopes.size();
        this.slopeRects = new ArrayList(size);
        this.routeSlopeDateSets = new ArrayList(size);
        int i = 0;
        while (i < size) {
            RouteSlope routeSlope = routeSlopes.get(i);
            int sampleEndIndex = routeSlope.getSampleEndIndex() - 1;
            if (routeSlope.getLevel().equals("Na")) {
                context = context2;
            } else {
                Context context3 = context2;
                LineDataSet buildDashVerticalLine = buildDashVerticalLine(context3, routeSlope.getSampleStartIndex(), lushuPoints, distances, routeSlope.getLevel());
                LineDataSet buildDashVerticalLine2 = buildDashVerticalLine(context3, sampleEndIndex, lushuPoints, distances, routeSlope.getLevel());
                RectF rectF = new RectF();
                context = context2;
                LineDataSet buildSlopeDataSet = buildSlopeDataSet(context3, routeSlope, lushuPoints, distances, rectF, drawMarker);
                this.routeSlopeDateSets.add(buildSlopeDataSet);
                rectF.union(rectF.left, rectF.top - f);
                rectF.union(rectF.left, rectF.bottom + f);
                this.slopeRects.add(rectF);
                if (buildDashVerticalLine != null) {
                    arrayList.add(buildDashVerticalLine);
                }
                if (buildDashVerticalLine2 != null) {
                    arrayList.add(buildDashVerticalLine2);
                }
                if (buildSlopeDataSet != null) {
                    arrayList.add(buildSlopeDataSet);
                }
            }
            i++;
            context2 = context;
        }
        try {
            this.mChart.setData(new LineData((ILineDataSet[]) arrayList.toArray(new LineDataSet[arrayList.size()])));
        } catch (Exception e) {
            e.printStackTrace();
        }
        this.mChart.postInvalidate();
    }

    private LineDataSet buildAltitudeDataSet(List<RouteBookPoint> lushuPoints, List<Float> distances) {
        int size = lushuPoints.size();
        ArrayList arrayList = new ArrayList(size);
        for (int i = 0; i < size; i++) {
            RouteBookPoint lushuPoint = lushuPoints.get(i);
            arrayList.add(new Entry(distances.get(i), (float) lushuPoint.getAltitude(), lushuPoint));
        }
        return new LineDataSet(arrayList, "");
    }

    private LineDataSet buildSlopeDataSet(Context context, RouteSlope slope, List<RouteBookPoint> lushuPoints, List<Float> distances, RectF rectF, boolean drawMarker) {
        Parcelable entry;
        int sampleStartIndex = slope.getSampleStartIndex();
        int sampleEndIndex = slope.getSampleEndIndex() - 1;
        if (sampleEndIndex < 0) {
            sampleEndIndex = 0;
        }
        ArrayList arrayList = new ArrayList((sampleEndIndex - sampleStartIndex) + 1);
        boolean z = false;
        while (sampleStartIndex < sampleEndIndex) {
            if (sampleStartIndex >= 0 && sampleStartIndex < lushuPoints.size()) {
                Float f = distances.get(sampleStartIndex);
                float altitude = (float) lushuPoints.get(sampleStartIndex).getAltitude();
                arrayList.add(new Entry(f, altitude, slope));
                if (z) {
                    rectF.union(f, altitude);
                } else {
                    rectF.set(f, altitude, f, altitude);
                    z = true;
                }
            }
            sampleStartIndex++;
        }
        Float f2 = distances.get(sampleEndIndex);
        float altitude2 = (float) lushuPoints.get(sampleEndIndex).getAltitude();
        if (drawMarker) {
            entry = new MarkerEntry(f2, altitude2, slope, slope.getLevel());
        } else {
            entry = new Entry(f2, altitude2, slope);
        }
        arrayList.add(entry);
        if (z) {
            rectF.union(distances.get(sampleEndIndex), altitude2);
        } else {
            rectF.set(f2, altitude2, f2, altitude2);
        }
        LineMarkerDataSet lineMarkerDataSet = new LineMarkerDataSet(arrayList, slope.getLevel());
        lineMarkerDataSet.setColor(context.getResources().getColor(R.color.route_chart_slope_line_color));
        lineMarkerDataSet.setDrawCircles(false);
        lineMarkerDataSet.setDrawValues(false);
        lineMarkerDataSet.setLineWidth(2.0f);
        lineMarkerDataSet.setDrawFilled(false);
        lineMarkerDataSet.setDrawHighlightIndicators(false);
        lineMarkerDataSet.setHighlightEnabled(true);
        lineMarkerDataSet.setAxisDependency(YAxis.AxisDependency.LEFT);
        lineMarkerDataSet.setMakerColor(context.getResources().getColor(R.color.route_chart_slope_level_color));
        lineMarkerDataSet.setMarkerTextSize(10.0f);
        lineMarkerDataSet.setMarkerTextColor(-1);
        lineMarkerDataSet.setVerticalPadding(12.0f);
        lineMarkerDataSet.setMarkerRadius(8.0f);
        return lineMarkerDataSet;
    }

    private LineDataSet buildDashVerticalLine(Context context, int index, List<RouteBookPoint> lushuPoints, List<Float> distances, String level) {
        if (index < 0 || index >= distances.size()) {
            return null;
        }
        ArrayList arrayList = new ArrayList(0);
        float floatValue = distances.get(index);
        Entry entry = new Entry(floatValue, (float) lushuPoints.get(index).getAltitude());
        entry.setData(level);
        arrayList.add(entry);
        arrayList.add(new Entry(floatValue, this.mChart.getYChartMin()));
        LineDataSet lineDataSet = new LineDataSet(arrayList, "");
        lineDataSet.setColor(context.getResources().getColor(R.color.white));
        lineDataSet.setDrawCircles(false);
        lineDataSet.setDrawValues(false);
        lineDataSet.setLineWidth(1.0f);
        lineDataSet.enableDashedLine(Density.dp2px(context, 3.0f), Density.dp2px(context, 2.0f), 0.0f);
        lineDataSet.setDrawFilled(false);
        lineDataSet.setHighlightEnabled(false);
        lineDataSet.setAxisDependency(YAxis.AxisDependency.LEFT);
        return lineDataSet;
    }

    public void zoomSlope(int index) {
        zoomSlope(index, false);
    }

    public void zoomSlope(int index, boolean fromChar) {
        List<RouteSlope> list;
        if (this.altitudeDataSet == null || this.distances == null || (list = this.routeSlopes) == null || index < 0 || index >= list.size()) {
            return;
        }
        RouteSlope routeSlope = this.routeSlopes.get(index);
        int sampleStartIndex = routeSlope.getSampleStartIndex();
        int sampleEndIndex = routeSlope.getSampleEndIndex() - 1;
        if (sampleStartIndex == sampleEndIndex) {
            if (sampleEndIndex < this.distances.size() - 1) {
                sampleEndIndex++;
            } else if (sampleStartIndex > 0) {
                sampleStartIndex++;
            }
        }
        float floatValue = this.distances.get(sampleStartIndex);
        float floatValue2 = this.distances.get(sampleEndIndex);
        float f = floatValue2 - floatValue;
        scaleChart(f <= 0.0f ? 100.0f : (this.mChart.getXChartMax() - this.mChart.getXChartMin()) / (f * 1.04f), (floatValue + floatValue2) / 2.0f);
        OnSlopeSelectedListener onSlopeSelectedListener = this.onSlopeSelectedListener;
        if (onSlopeSelectedListener != null) {
            onSlopeSelectedListener.onSlopeSelected(index, routeSlope, fromChar);
        }
    }

    public void collapsedSlopes() {
        List<Float> list = this.distances;
        if (list == null || list.isEmpty()) {
            return;
        }
        float floatValue = this.distances.get(0);
        List<Float> list2 = this.distances;
        scaleChart(1.0f, (floatValue + list2.get(list2.size() - 1)) / 2.0f);
    }

    private void scaleChart(float scaleX, final float centerX) {
        float f;
        float minScaleX;
        OnChartScaleListener onChartScaleListener;
        YAxis.AxisDependency axisDependency = this.altitudeDataSet.getAxisDependency();
        ViewPortHandler viewPortHandler = this.mChart.getViewPortHandler();
        MPPointD valuesByTouchPoint = this.mChart.getValuesByTouchPoint(viewPortHandler.contentLeft(), viewPortHandler.contentTop(), axisDependency);
        if (scaleX > viewPortHandler.getMaxScaleX()) {
            minScaleX = viewPortHandler.getMaxScaleX();
        } else if (scaleX < viewPortHandler.getMinScaleX()) {
            minScaleX = viewPortHandler.getMinScaleX();
        } else {
            f = scaleX;
            LineChart lineChart = this.mChart;
            float f2 = f;
            this.mChart.addViewportJob(new ChartAnimatedZoomJob(viewPortHandler, lineChart, lineChart.getTransformer(axisDependency), this.mChart.getAxis(axisDependency), this.mChart.getXAxis().mAxisRange, f, 1.0f, viewPortHandler.getScaleX(), viewPortHandler.getScaleY(), centerX, (this.altitudeDataSet.getYMin() + this.altitudeDataSet.getYMax()) / 2.0f, (float) valuesByTouchPoint.x, (float) valuesByTouchPoint.y, 500L));
            MPPointD.recycleInstance(valuesByTouchPoint);
            onChartScaleListener = this.scaleListener;
            if (onChartScaleListener == null) {
                onChartScaleListener.onScale(f2, 1.0f);
                return;
            }
            return;
        }
        f = minScaleX;
        LineChart lineChart2 = this.mChart;
        float f22 = f;
        this.mChart.addViewportJob(new ChartAnimatedZoomJob(viewPortHandler, lineChart2, lineChart2.getTransformer(axisDependency), this.mChart.getAxis(axisDependency), this.mChart.getXAxis().mAxisRange, f, 1.0f, viewPortHandler.getScaleX(), viewPortHandler.getScaleY(), centerX, (this.altitudeDataSet.getYMin() + this.altitudeDataSet.getYMax()) / 2.0f, (float) valuesByTouchPoint.x, (float) valuesByTouchPoint.y, 500L));
        MPPointD.recycleInstance(valuesByTouchPoint);
        onChartScaleListener = this.scaleListener;
//        if (onChartScaleListener == null) {
//        }
    }

    public List<RouteBookPoint> getAltitudePoints() {
        return this.lushuPoints;
    }

    public List<Float> getDistances() {
        return this.distances;
    }

    public List<RouteSlope> getRouteSlopes() {
        return this.routeSlopes;
    }
}
